#include <SFML/Graphics.hpp>
#include "../include/HeaderScreen.hpp"
#include "../include/Palette.hpp"

Palette::Palette(int widthParam,int y,sf::Image &sprite){
    this->sprite.SetImage(sprite);
    this->width = widthParam;

    this->position.Left = POSBACKX+(LARGSCREEN/2)-((LARGSPRITEG+widthParam*LARGSPRITEC+LARGSPRITED)/2);
    this->position.Top = y;
    this->position.Right = position.Left+getWidthPx();
    this->position.Bottom = y+HAUTSPRITEPALETTE;
    this->sprite.SetPosition(400-(this->getWidthPx()),y);

	this->tabPosition[0].Left = 0;
	this->tabPosition[0].Top = 0;
	this->tabPosition[0].Right = LARGSPRITEG;
	this->tabPosition[0].Bottom = HAUTSPRITEPALETTE;

	this->tabPosition[1].Left = LARGSPRITEG;
	this->tabPosition[1].Top = 0;
	this->tabPosition[1].Right = LARGSPRITEG+LARGSPRITEC;
	this->tabPosition[1].Bottom = HAUTSPRITEPALETTE;

	this->tabPosition[2].Left = LARGSPRITEG+LARGSPRITEC;
	this->tabPosition[2].Top = 0;
	this->tabPosition[2].Right = LARGSPRITEG+LARGSPRITEC+LARGSPRITED;
	this->tabPosition[2].Bottom = HAUTSPRITEPALETTE;
}

Palette::~Palette(){
}

int Palette::getWidth(){
    return this->width;
}

int Palette::getWidthPx(){
    return LARGSPRITEG+width*LARGSPRITEC+LARGSPRITED;
}

void Palette::setWidth(int width){
    if(width >= MINWIDTH && width <= MAXWIDTH){
        this->width = width;
        this->position.Right = position.Left+getWidthPx();
    }
}

void Palette::setPosition(float x){
    //if(x-(this->getWidthPx()/2) >= POSBACKX && x+(this->getWidthPx()/2) <= POSBACKX+LARGBACKGROUND){
        this->sprite.SetX(this->getWidthPx());
        position.Left = x;
        position.Right = position.Left+getWidthPx();
    //}
}

sf::Sprite &Palette::getSprite(){
	return this->sprite;
}

sf::IntRect Palette::getRect(int i){
    return this->tabPosition[i];
}

sf::FloatRect Palette::getPositionObj(){
    return this->position;
}

int Palette::getWidthMiddlePx(){
	return LARGSPRITEC;
}

int Palette::getHeightMiddlePx(){
    return 0;
}
